package com.hualan.bean;

import com.hualan.util.Pinyin4j;
import com.hualan.util.Utils;

import java.util.Objects;

public class Contact implements Comparable{
    //名字
    private String name;
    //分组
    private Character groupName;
    //手机号码
    private String phone;

    public Contact() {
    }

    /**
     * 全参构造
     * @param name 名字
     * @param phone
     */
    public Contact(String name, String phone) {
        this.name = name;
        this.phone = phone;
        // 设置分组名
        groupName = Utils.getChar0(name);
    }

    @Override
    public int compareTo(Object o) {
        Contact temp = (Contact) o;
        return name.compareTo(temp.getName());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Contact contact = (Contact) o;
        return Objects.equals(name, contact.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
        //更新分组名
        groupName = Utils.getChar0(name);
    }

    public Character getGroupName() {
        return groupName;
    }

    @Override
    public String toString() {
        return name + "(" + phone + ")";
    }
}
